package com.sdtv.mediunfusion.utils;

import android.widget.EditText;

import com.sdtv.mediunfusion.base.config.MediumApplication;
import com.sdtv.mediunfusion.bean.UserIdentify;

import java.lang.reflect.Method;

/**
 * @ProjectName: MediunFusion
 * @Package: com.sdtv.mediunfusion.utils
 * @ClassName: Utils
 * @Description: java类作用描述
 * @Author: 小郭同学
 * @CreateDate: 2019-08-05 10:37
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class Utils {

    /**
     * 拼接shareprefence所使用的KEY
     * 该KEY值是与用户以及APP相关联
     *
     * @param original
     * @return
     */
    public static String getSharePrefenceKey(String original) {
        original = getValueByKey("getLoaclUserKey") + original;
        return original;
    }

    /**
     * 根据KEY获取用户的基本信息  getRealName
     */
    public static String getValueByKey(String key) {
        UserIdentify userIdentify = MediumApplication.getUserIdentify();
        String value = null;
        if (null != userIdentify) {
            value = userIdentify.getLoaclUserKey();
            try {
                Method method = userIdentify.getClass().getDeclaredMethod(key);
                value = (String) method.invoke(userIdentify);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            //到缓存文件中获取值
            String temp_key = key.substring(0, 4).toLowerCase();
            temp_key = temp_key.substring(temp_key.length() - 1);
            temp_key = temp_key + key.substring(4);
            value = SharedPreUtils.getPreStringInfo(MediumApplication.getContext(), temp_key);
        }
        return value;
    }

    /**
     * 设置editText不可编辑
     *
     * @param editText
     */
    public static void disableEditText(EditText editText) {
        editText.setFocusableInTouchMode(false);
        editText.setFocusable(false);
    }


}
